import { VM } from 'vm2'
import { log } from 'console'
export default  function runScript(script: string): { success: boolean; output: any } {
  log(`run-script: ${script}`)
  // 使用 vm2 执行脚本;

  const vm = new VM({
    sandbox: { console }
  })

  try {
    // log('vm', vm)
    const result = vm.run(script)
    log('result', result)
    return { success: true, output: result }
  } catch (error) {
    log('error', error)
    return { success: false, output: error instanceof Error ? error.message : String(error) }
  }
}
